//
//  EditTaskSortViewController.m
//  OAProject
//
//  Created by yhj on 2017/3/28.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "EditTaskSortViewController.h"

@interface EditTaskSortViewController ()<UITextViewDelegate>

@property(nonatomic,strong)UIView *mainView;

@property(nonatomic,strong)UITextView *textView;

@end

@implementation EditTaskSortViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor=WhiteColor;

    self.automaticallyAdjustsScrollViewInsets=NO;

    self.title=@"修改分类";

    [self.view addSubview:self.mainView];

    // 确认提交
    [AppUI initNavigationItem:self.navigationItem andWithText:@"确  认" andTextColor:WhiteColor andIsRight:YES withBlock:^{

        [API EdidSortWithSortID:self.model.sortID sortName:self.model.target_name memo:self.textView.text success:^(id res) {

            if ([res[@"rt"] isEqual:@(1)])
            {
              [self.view makeToast:@"修改成功" duration:1 position:CSToastPositionCenter];

                dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(1.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                    [self.navigationController popViewControllerAnimated:NO];
                });
            }
            else
            {
                [self.view makeToast:res[@"error"] duration:1 position:CSToastPositionCenter];
            }

        } failure:^(NSInteger stateCode) {

        }];
    }];
}


-(UIView *)mainView
{
    if (!_mainView) {
        _mainView=[UIView new];
        _mainView=[[UIView alloc]initWithFrame:CGRectMake(0,64,APPW,0)];
        _mainView.backgroundColor=WhiteColor;
        setViewHeight_Add(_mainView,kmargin*2);

        // 分类名称
        UILabel *projectNameLabel=[self.mainView getLabelWithText:@"分类名称(不能修改)" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.mainView addSubview:projectNameLabel];
        projectNameLabel.frame=CGRectMake(kmargin*2,_mainView.frame.size.height,APPW/2,kmargin*2);
        setViewHeight_Add(_mainView,kmargin*2);

        UILabel *projectNameDetailLabel=[self.mainView getLabelWithText:self.model.target_name font:Font_Number(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.mainView addSubview:projectNameDetailLabel];
        projectNameDetailLabel.frame=CGRectMake(kmargin*2,_mainView.frame.size.height+kmargin/2,APPW/2,kmargin*2);
        setViewHeight_Add(_mainView,kmargin*4);

        // 分类描述
        UILabel *projectDesLabel=[self.mainView getLabelWithText:@"分类描述" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.mainView addSubview:projectDesLabel];
        projectDesLabel.frame=CGRectMake(kmargin*2,_mainView.frame.size.height,APPW/2,kmargin*2);
        setViewHeight_Add(_mainView,kmargin*2);

        _textView=[[UITextView alloc]initWithFrame:CGRectMake(kmargin*3/2,_mainView.frame.size.height,APPW-kmargin*3,APPH/5)];
        _textView.text=self.model.memo;
        _textView.delegate=self;
        _textView.font=Font_Number(16);
//        ViewBorderRadius(_textView,2,1,MAIN_BACK_COLOR);
        _textView.textColor=DarkGreyColor;
        [self.mainView addSubview:_textView];
        setViewHeight_Add(_mainView,APPH/5);
        
    }
    return _mainView;
}

// 点击return键时候键盘下去
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

@end
